<?php
apf_require_controller("Abstract");

class Portal_Home_CenterController extends AbstractController {

    public function handle_request() {

        $uid = $this->get_user_id();
        $projects = $this->get_data_bll()->get_sort_projects($uid);
        $id = $this->request->get_parameter("id");
        if (!empty($id) && key_exists($id, $projects)){
            $this->get_data_bll()->inc_view_count($uid, $id);
            $this->response->redirect($projects[$id]['url']);
        }

        $this->request->set_attribute('projects', $projects);
        return "Portal_Home_Center";
    }

    private function get_data_bll(){
        if (!$this->data_bll || !$this->data_bll instanceof Bll_Portal_HomeProjectView){
            apf_require_class("Bll_Portal_HomeProjectView");
            $this->data_bll = new Bll_Portal_HomeProjectView();
        }
        return $this->data_bll;
    }
}